home *** CD-ROM | disk | FTP | other *** search
- /****
- * CIntelligentWindow.c
- *
- * This class makes the Window a little more intelligent.
- *
- * Copyright © 1993 Quipus, by Mårten Sörliden. All rights reserved.
- *
- ****/
-
- #include <TBUtilities.h>
- #include <Packages.h>
- #include <Constants.h>
- #include <CList.h>
- #include <CIntelligentWindow.h>
- #include <CIntelligentDecorator.h>
- #include <CIntelligentScrollPane.h>
-
- #define kMinWindWidth 125
- #define kMinWindHeight 88 // = 125 / Sqrt(2)
-
- #define kLeftZoomSizeOffset 66
- #define kTopZoomSizeOffset 47
- #define kRightZoomSizeOffset -7
- #define kBottomZoomSizeOffset -25
-
- /*** Global Variables ***/
-
- extern CDecorator *gDecorator;
-
-
- /** Construction and destruction methods **/
-
- void CIntelligentWindow::IIntelligentWindow(short WINDid, Boolean aFloating, CDesktop *anEnclosure, CDirector *aSupervisor)
- {
- IWindow(WINDid, aFloating, anEnclosure, aSupervisor);
- sizeRect.left = kMinWindWidth;
- sizeRect.top = kMinWindHeight;
- wNum = 0;
- stdStateChanged = FALSE;
- lastDirection = 0;
- }
-
- void CIntelligentWindow::Dispose(void)
- {
-
- inherited::Dispose();
- }
-
-
- /** Accessing methods **/
-
- // override
- void CIntelligentWindow::SetTitle(Str255 theTitle)
- {
- Str255 wTitle;
- Rect portRect;
- Rect portBitBounds;
-
- GetTitle(wTitle);
- if (!IUEqualString(wTitle, theTitle))
- wNum = 0;
- // The portRect is saved and restored.
- // If the title of the window is named ie '92-06-19' the size of the window will be changed.
- portRect = (*macPort).portRect;
- portBitBounds = (*macPort).portBits.bounds;
- inherited::SetTitle(theTitle);
- (*macPort).portRect = portRect;
- (*macPort).portBits.bounds = portBitBounds;
- }
-
- void CIntelligentWindow::SetDefaultTitle()
- {
- Str255 wTitle;
- Str255 wNumber;
-
- if (wNum == 0)
- if (member(gDecorator, CIntelligentDecorator))
- wNum = ((CIntelligentDecorator*)gDecorator)->GetWNum();
- else
- wNum = gDecorator->GetWCount();
- GetTitle(wTitle);
- NumToString(wNum, wNumber);
- ConcatPStrings(wTitle, (StringPtr) "\p ");
- ConcatPStrings(wTitle, wNumber);
- inherited::SetTitle(wTitle);
- }
-
- short CIntelligentWindow::GetWNum()
- {
- return(wNum);
- }
-
- void CIntelligentWindow::SetStdState(Rect *aStdState)
- {
- WStateData **zoomData;
- int leftMargin, topMargin;
- Rect zoomSizeRect;
-
- zoomData = (WStateData**) ((WindowPeek)macPort)->dataHandle;
- leftMargin = LEFT_SMARGIN - 1;
- topMargin = TOP_SMARGIN + GetMBarHeight() - 1;
- zoomSizeRect = sizeRect;
- SetRect(&zoomSizeRect, sizeRect.left + kLeftZoomSizeOffset, sizeRect.top + kTopZoomSizeOffset,
- sizeRect.right + kRightZoomSizeOffset, sizeRect.bottom + kBottomZoomSizeOffset);
- // Change the size of aStdState if neccecray
- if (aStdState->right - aStdState->left < zoomSizeRect.left)
- aStdState->right = aStdState->left + zoomSizeRect.left;
- if (aStdState->right - aStdState->left > zoomSizeRect.right)
- aStdState->right = aStdState->left + zoomSizeRect.right;
- if (aStdState->bottom - aStdState->top < zoomSizeRect.top)
- aStdState->bottom = aStdState->top + zoomSizeRect.top;
- if (aStdState->bottom - aStdState->top > zoomSizeRect.bottom)
- aStdState->bottom = aStdState->top + zoomSizeRect.bottom;
- if ((leftMargin > aStdState->left) || (topMargin > aStdState->top) ||
- (leftMargin + zoomSizeRect.right < aStdState->right) ||
- (topMargin + zoomSizeRect.bottom < aStdState->bottom)) {
- // Move window to upper left corner
- aStdState->right = aStdState->right + leftMargin - aStdState->left;
- aStdState->left = leftMargin;
- aStdState->bottom = aStdState->bottom + topMargin - aStdState->top;
- aStdState->top = topMargin;
- }
- SetPort(macPort);
- ForceNextPrepare();
- if (!EqualRect(&(**zoomData).stdState, aStdState)) {
- (**zoomData).stdState = *aStdState;
- stdStateChanged = TRUE;
- }
- }
-
-
- /** Size and location methods **/
-
- // Override
- void CIntelligentWindow::Drag(EventRecord *macEvent)
- {
- inherited::Drag(macEvent);
- UpdateUserState();
- }
-
- // Override
- void CIntelligentWindow::Resize(EventRecord *macEvent)
- {
- inherited::Resize(macEvent);
- UpdateUserState();
- }
-
- // Override
- void CIntelligentWindow::Zoom(short direction)
- {
- WStateData **zoomData;
-
- zoomData = (WStateData**) ((WindowPeek)macPort)->dataHandle;
- if (EqualRect(&(**zoomData).userState, &(**zoomData).stdState))
- return;
- if ((lastDirection == inZoomIn) && (direction == inZoomIn))
- return;
- if ((stdStateChanged) && (direction == inZoomIn))
- direction = inZoomOut;
- inherited::Zoom(direction);
- stdStateChanged = FALSE;
- lastDirection = direction;
- }
-
- void CIntelligentWindow::UpdateStdState()
- {
- WStateData **zoomData;
- Rect theStdState;
- CView *theView;
- long n, i;
- LongRect unionFrame;
- LongRect theFrame;
-
- if (((WindowPeek)macPort)->spareFlag) {
- /* Get standard state rectangle */
- zoomData = (WStateData**) ((WindowPeek)macPort)->dataHandle;
- SetLongRect(&unionFrame, 0L, 0L, 0L, 0L);
- n = itsSubviews->GetNumItems();
- for (i = 1; i <= n; i++) {
- theView = (CView *)itsSubviews->NthItem(i);
- if (member(theView, CIntelligentScrollPane)) {
- ((CIntelligentScrollPane *)theView)->GetPreferedFrame(&theFrame);
- UnionLongRect(&theFrame, &unionFrame, &unionFrame);
- }
- }
- if (!EmptyLongRect(&unionFrame)) {
- theStdState = (**zoomData).userState;
- theStdState.right = unionFrame.right + theStdState.left - 2;
- theStdState.bottom = unionFrame.bottom + theStdState.top - 2;
- SetStdState(&theStdState);
- }
- }
- }
-
- void CIntelligentWindow::UpdateUserState()
- {
- Rect windowRect;
- WStateData **zoomData;
-
- if (((WindowPeek)macPort)->spareFlag) {
- zoomData = (WStateData**) ((WindowPeek)macPort)->dataHandle;
- SetPort(macPort);
- ForceNextPrepare();
- windowRect = macPort->portRect;
- LocalToGlobal(&topLeft(windowRect));
- LocalToGlobal(&botRight(windowRect));
- (**zoomData).userState = windowRect;
- }
- }
-